package com.czk.receiver;

import com.czk.common.rabbit.constant.MqConst;
import com.czk.common.rabbit.constant.RabbitConstant;
import com.czk.common.rabbit.service.RabbitService;
import com.czk.model.hosp.Schedule;
import com.czk.service.ScheduleService;
import com.czk.vo.msm.MsmVo;
import com.czk.vo.order.OrderMqVo;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/11/29 23:06
 */
@Component
@RabbitListener(queues = RabbitConstant.QUEUE_ORDER)
public class MyHospitalReceiver {
    @Autowired
    private ScheduleService scheduleService;
    @Autowired
    private RabbitService rabbitService;

    @RabbitHandler
    public void process(OrderMqVo orderMqVo) {
        System.out.println("开始扣库存了");
        // 下单成功，更细预约数
        Schedule schedule = scheduleService.getScheduleById(orderMqVo.getScheduleId());
        schedule.setReservedNumber(orderMqVo.getReservedNumber());
        schedule.setAvailableNumber(orderMqVo.getAvailableNumber());
        scheduleService.update(schedule);
        // 发送短信
        MsmVo msmVo = orderMqVo.getMsmVo();
        System.out.println(msmVo);
        //
        if (null != msmVo) {
            // 发送短信
            rabbitService.sendMessage(RabbitConstant.EXCHANGE_DIRECT_MSM, RabbitConstant.ROUTING_MSM_ITEM, msmVo.getParam().get("msg"));
        }
    }
}
